#!/bin/bash
sandboxdir=$(dirname $0)
. $sandboxdir/sb_vars.sh
. $sandboxdir/sb_common.sh

pre_installation direct
check_exit_code

SERVICE=$1
[ -z "$SERVICE" ] && SERVICE=directsandbox

export HOW_MANY_NODES=$2
[ -z "$HOW_MANY_NODES" ] && export HOW_MANY_NODES=2

if [ $HOW_MANY_NODES -lt 2 ]
then
    echo "At least 2 nodes are required"
    exit 1
fi

$sandboxdir/sb_make_sandboxes

if [ -n "$USE_INI" ]
then
    install_with_ini_files
else
    MYSQL_MASTER_PORT=$(($MYSQL_BASE_PORT+1))

    for NODE in $(seq 2 $HOW_MANY_NODES)
    do
        DELTA=$(($NODE*10))
        configure_defaults $NODE
        configure_direct_slave $SERVICE $(($THL_BASE_PORT+$DELTA)) --direct-datasource-port=$MYSQL_MASTER_PORT
        tpm_install
    done
fi

post_installation direct

